<template>
  <div class="home">
    <!-- Banner组件 -->
    <BannerItem></BannerItem>
    <SqbxNav></SqbxNav>
    <SqbxOthers></SqbxOthers>
    <!-- 签到弹窗 -->
    <section class="dialog" v-if="isShow">
      <div class="make" @touchmove.prevent></div>
      <div class="dialog-conent" @touchmove.prevent>
        <div class="list-name">
          <img
            v-bind:src="info.portrait?info.portrait:'https://gw.alicdn.com/tfs/TB15Q0lOmzqK1RjSZFHXXb3CpXa-400-400.png'"
            alt
          >
          <p>{{info.user_name}}</p>
        </div>
        <div class="dialog-num">
          <p>签到成功 + {{sing.score || 0}} 积分</p>
          <p>继续加油</p>
        </div>
        <div style="text-align: center;">
          <div class="dialog-btn" @click="isShow=!isShow">知道了</div>
        </div>
      </div>
    </section>
  </div>
</template>
<script>
import BannerItem from "./banner/banner"; //导入banner组件
import SqbxNav from "./nav/sqbxNav"; //导入banner组件
import SqbxOthers from "./other/sqbxOthers"; //导入标题组件
import { signIn } from "@/api/home";
import { checkUserSign } from "@/api/login";
import { article_listAllArticletype } from "@/api/article";

export default {
  name: "Home2",
  components: {
    SqbxOthers,
    BannerItem,
    SqbxNav
  },
  data() {
    return {
      sing: {},
      info: JSON.parse(localStorage.getItem("user")),
      isShow: false,
      companyId: localStorage.getItem("companyId") - 0,
      listQuery: {
        current: 1,
        limit: 8,
        company_id: localStorage.getItem("companyId") - 0
      },
      dataList: [],
      topicType: []
    };
  },
  methods: {
    link(e) {
      this.$router.push({
        path: "/topicType",
        query: {
          id: e.id,
          name: e.articletype_name,
          nameLink: "articleAdd"
        }
      });
    },
    link2() {
      this.$toast("敬请期待");
    },
    openLink(item) {
      if (item.type == "active") {
        this.$router.push({
          path: "/ActivityDetail",
          query: { id: item.id, status: item.active_status }
        });
      }
    },
    async sign() {
      try {
        let userid = JSON.parse(localStorage.getItem("user"));
        let parment = {
          user_id: userid.id,
          company_id: userid.company_id
        };
        let res = await signIn(parment);
        if (res.data.status == 100) {
          this.sing = res.data.data;
          this.isShow = true;
        }
      } catch (error) {
        if (error.status == 101) {
          // this.$toast("已签到!");
        }
      }
    },
    async getCheckUserSign() {
      try {
        let res = await checkUserSign({});
        if (res.data.status == 100) {
          if (res.data.data == true) {
            this.sign();
          } else {
            // this.sign()
          }
        }
      } catch (error) {
        if (error.status == 101) {
          // this.$toast("已签到!");
        }
      }
    }
  },
  created() {
    setTimeout(() => {
      if (localStorage.getItem("companyId") == 6) {
        this.getCheckUserSign();
      }
      this.info.portrait = localStorage.getItem("headimgurl");
    }, 1000);
  }
};
</script>
<style lang="scss" scoped>
@import "Home3";
@import "./sign/sign.scss";
</style>
